//
//  ProductOrderViewController.m
//  WorkNest
//
//  Created by qbm360 on 15/7/15.
//  Copyright (c) 2015年 nest. All rights reserved.
//

#import "ProductOrderViewController.h"
#import "OrderCountView.h"
#import "PriceQueryChooseViewController.h"
#import "AddressViewController.h"

@interface ProductOrderViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) NSArray *style;

@end

@implementation ProductOrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"orderTitle"]];
    self.navigationItem.titleView  = imageView;
    self.style = @[@"白色/S", @"白色/M", @"白色/L", @"白色/XL", @"红色/S", @"红色/M"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - action methods
- (IBAction)joinShoppingCart:(id)sender {
}

- (IBAction)paymentButton:(id)sender {
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *productOrderCellIdentifier = @"ProductOrderCell";
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:productOrderCellIdentifier];
    [cell.textLabel setFont:[UIFont systemFontOfSize:14]];
    [cell.textLabel setTextColor:[UIUtil colorWithHexString:appFontColor]];
    if (indexPath.row == 0) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(24, 14, SCREEN_WIDTH - 48, (self.style.count + 1) * 28 - self.style.count - 1)];
        view.layer.masksToBounds = YES;
        view.layer.cornerRadius = 6.0;
        view.layer.borderWidth = 1;
        view.layer.borderColor = [[UIUtil colorWithHexString:@"#bdbaba"] CGColor];
        for (int i = 0; i < self.style.count + 1; i++) {
            if (i == 0) {
                OrderCountView *countView = [[OrderCountView alloc] initWithFrame:CGRectMake(0, 0, view.frame.size.width, 28) ifFirstView:YES];
                countView.styleString = @"款式";
                [view addSubview:countView];
            } else  {
                OrderCountView *countView = [[OrderCountView alloc] initWithFrame:CGRectMake(0, 28 * i - (1 + i), SCREEN_WIDTH - 48, 28) ifFirstView:NO];
                countView.styleString = [self.style objectAtIndex:i-1];
                countView.layer.borderWidth = 1;
                countView.layer.borderColor = [[UIUtil colorWithHexString:@"#bdbaba"] CGColor];
                [view addSubview:countView];
            }
        }
        [cell addSubview:view];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    } else {
        cell.selectionStyle = UITableViewCellSelectionStyleDefault;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        if (indexPath.row == 1) {
            cell.textLabel.text = @"订单说明";
        } else if (indexPath.row == 2){
            cell.textLabel.text = @"选择收货地址";
        } else {
            cell.textLabel.text = @"订单要求工期";
        }
    }
    return cell;
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        return (self.style.count + 1) * 28 + 28 - self.style.count - 1;
    } else {
        return 44;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 1) {
        PriceQueryChooseViewController *view = [[PriceQueryChooseViewController alloc] init];
        view.choose = @"0";
        view.positionArray = @[@"",@"",@"订单说明"];
        view.chooseBlock = ^(NSString *title) {
            
        };
        [self.navigationController pushViewController:view animated:YES];
    } else if (indexPath.row == 2) {
        AddressViewController *view = [[AddressViewController alloc] init];
        view.addressTitle = @"选择收货地址";
        view.ifModify = NO;
        [self.navigationController pushViewController:view animated:YES];
    } else if (indexPath.row == 3) {
        PriceQueryChooseViewController *view = [[PriceQueryChooseViewController alloc] init];
        view.choose = @"0";
        view.ifChooseDate = YES;
        view.positionArray = @[@"",@"",@"订单要求工期"];
        view.chooseBlock = ^(NSString *title) {
            
        };
        [self.navigationController pushViewController:view animated:YES];
    }
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}

@end
